#include <signal.h>

#include <iostream>
#include <unistd.h>
#include <thread>
#include <string>

#include "dds_api.h"
#include "dds_common.h"

using namespace minieye::DDS;

void on_read_data(const char* topic, size_t index, void* ptr, size_t size, void *user) {
  std::string content((char*)ptr, size);
  std::cout << "package received, idx: "
            << index
            << ", frame size: "
	    << size
            << ", content: "
            << content
   	    << ", tid: "
	    << std::this_thread::get_id()
            << std::endl;
}

int main() 
{
  std::cout << "client.cpp main tid: " << std::this_thread::get_id() << std::endl;

  const std::string configPath = "/home/mini/code/linux_hjh/minieye_dds/config.json";
  
  Context ctx(configPath, true);
  Reader reader(&ctx, "test", on_read_data);

  for(int i = 0; i < 20; i++){
    std::this_thread::sleep_for(std::chrono::seconds(1));
    std::cout << "client sleep: i = " << i << std::endl;
  }

  ctx.DisableEventLoop();
  std::cout << "Client: DisbaleEventLoop() pid: " << getpid() << std::endl;

  //for(int j = 0; j < 10; j++)
  //{
    //std::this_thread::sleep_for(std::chrono::seconds(1));
    //std::cout << "client sleep: j = " << j << std::endl;
  //}
  while(1){}

  return 0;
}
